package com.hmdp.interceptors;

import com.hmdp.utils.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

/**
 * @author 计算机系 ITAEM 摆渡人
 * @description
 * @date 2022/10/15 20:22
 */
@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //1.判断是否需要拦截
        if(Objects.isNull(UserHolder.getUser())){
            response.setStatus(401);
            return false;
        }
        return true;
    }
}
